package org.example.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.entity.Regularization;
import org.example.mapper.RegularizationMapper;
import org.example.entity.RegularizationVO;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class RegularizationService extends ServiceImpl<RegularizationMapper, Regularization> {

    /**
     * 分页查询并转换为VO对象
     */
    public Page<RegularizationVO> pageVO(Page<Regularization> page) {
        // 执行分页查询
        Page<Regularization> regularizationPage = this.page(page);

        // 转换为VO对象
        Page<RegularizationVO> voPage = new Page<>();
        voPage.setCurrent(regularizationPage.getCurrent());
        voPage.setSize(regularizationPage.getSize());
        voPage.setTotal(regularizationPage.getTotal());

        List<RegularizationVO> voList = regularizationPage.getRecords().stream().map(this::convertToVO).collect(Collectors.toList());
        voPage.setRecords(voList);

        return voPage;
    }

    /**
     * 转换实体类为VO对象
     */
    private RegularizationVO convertToVO(Regularization regularization) {
        RegularizationVO vo = new RegularizationVO();
        vo.setApplicationTime(regularization.getApplicationTime());
        vo.setWorkNumber(regularization.getEmployeeIdNumber());
        vo.setRegularizationName(regularization.getRegularizationName());
        vo.setDepartment(regularization.getDepartment());
        vo.setPosts(regularization.getPosts());
        vo.setEmploymentForm(regularization.getEmploymentForm());
        vo.setIdentityCard(regularization.getIdentityCard());
        vo.setOnboarding(regularization.getOnboarding());
        vo.setTurnPositive(regularization.getTurnPositive());
        vo.setSalary(regularization.getSalary());
        vo.setProbationarySalary(regularization.getProbationarySalary());
        vo.setDescription(regularization.getDescription());
        vo.setSelfEvaluation(regularization.getSelfEvaluation());
        vo.setAverageScore(regularization.getAverageScore());
        vo.setEvaluationLevel(regularization.getEvaluationLevel());
        vo.setSupervisor(regularization.getSupervisor());
        vo.setOfficialDate(regularization.getOfficialDate());
        vo.setHrConfirm(regularization.getHrConfirm());
        return vo;
    }
}